﻿#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
#endregion

namespace DotNetEngine.Input
{
    public enum PadState
    {
        JustPressed,
        Pressed
    }

    public class InputManager
    {
        protected static KeyboardState lastKeyboard;
        protected static GamePadState lastGamePad;

        public static void Update()
        {
            lastKeyboard = Keyboard.GetState();
            if (GamePad.GetState(PlayerIndex.One).IsConnected)
                lastGamePad = GamePad.GetState(PlayerIndex.One);
        }

        public static bool KeyboardKeyJustPressed(Keys key)
        {
            return (Keyboard.GetState().IsKeyDown(key) && lastKeyboard.IsKeyUp(key));
        }

        public static bool KeyboardKeyPressed(Keys key)
        {
            return Keyboard.GetState().IsKeyDown(key);
        }

        public static bool GamePadJustPressed(Buttons button)
        {
            if (!GamePad.GetState(PlayerIndex.One).IsConnected)
                return false;

            return GamePad.GetState(PlayerIndex.One).IsButtonDown(button) && lastGamePad.IsButtonUp(button);
        }

        public static bool GamePadPressed(Buttons button)
        {
            if (!GamePad.GetState(PlayerIndex.One).IsConnected)
                return false;

            return GamePad.GetState(PlayerIndex.One).IsButtonDown(button);
        } 
    }
}
